package com.bcn.login_mybatisplus_demo.pay.controller;

import java.util.HashMap;
import java.util.List;

import com.bcn.login_mybatisplus_demo.common.controller.BaseController;
import com.bcn.login_mybatisplus_demo.common.page.TableDataInfo;
import com.bcn.login_mybatisplus_demo.pay.domain.TAppPay;
import com.bcn.login_mybatisplus_demo.pay.service.ITAppPayService;
import com.bcn.login_mybatisplus_demo.pojo.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

/**
 * 日常账本Controller
 *
 * @author administrator
 * @date 2025-03-11
 */
@RestController
@RequestMapping("/system/pay")
public class TAppPayController extends BaseController {
    private String prefix = "system/pay";

    @Autowired
    private ITAppPayService tAppPayService;

    @GetMapping()
    public String pay() {
        return prefix + "/pay";
    }

    /**
     * 查询日常账本列表
     */
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody TAppPay tAppPay) {
        startPage();
        List<TAppPay> list = tAppPayService.selectTAppPayList(tAppPay);
        return getDataTable(list);
    }


    /**
     * 查询日常账本列表
     */
    @GetMapping("/listByDay")
    public R listByDay(TAppPay tAppPay) {
//        startPage();
        List<HashMap<String,Object>> stringHashMapHashMap = tAppPayService.selectTAppPayListByDay(tAppPay);
        return R.success(stringHashMapHashMap);
    }

    /**
     * 新增日常账本
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存日常账本
     */
    @PostMapping("/add")
    public R addSave(@RequestBody TAppPay tAppPay) {
        return R.success(tAppPayService.insertTAppPay(tAppPay));
    }

    /**
     * 修改日常账本
     */
    @GetMapping("/edit/{payId}")
    public String edit(@PathVariable("payId") Long payId, ModelMap mmap) {
        TAppPay tAppPay = tAppPayService.selectTAppPayById(payId);
        mmap.put("tAppPay", tAppPay);
        return prefix + "/edit";
    }

    /**
     * 修改保存日常账本
     */
    @PostMapping("/edit")
    public R editSave(@RequestBody TAppPay tAppPay) {
        return R.success(tAppPayService.updateTAppPay(tAppPay));
    }

    /**
     * 删除日常账本
     */
    @GetMapping("/remove/{id}")
    public R remove(@PathVariable("id")  Integer id) {
        return R.success(tAppPayService.deleteTAppPayById(id.longValue()));
    }
}
